package org.annoflow.filter;

import org.annoflow.audit.ContextTracker;
import org.annoflow.policy.PolicyType;
import org.annoflow.policy.PolicyManager;
import org.apache.log4j.Logger;

public class AuditFilter implements FilterPoint
{
	private static Logger logger = Logger.getLogger(AuditFilter.class);
	@Override
	public String getFilterCode()
	{
		return "org.annoflow.filter.AuditFilter.runFilter($args);";
	}
	public static void runFilter(Object[] args)
	{
		logger.info("AuditFilterExecuting");
		PolicyType policy = null;
		for(Object arg : args)
		{
			policy = null;
			if ((policy = PolicyManager.lookupClassPolicy(arg.getClass())) != null)
			{
				if (policy.audit(arg,AuditFilter.class.getName(),ContextTracker.getInstance().getFilterContext()))
				{
					System.out.println("AUDIT: " + policy.getClass().getSimpleName() + " " + arg);
				}
			}
		}
	}
	@Override
	public String getReturnFilterCode() {
		// TODO Auto-generated method stub
		return null;
	}

}
